import Vue from 'vue'
import VueRouter from 'vue-router'

// router.push 重写
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: "/index"
  },
  {
    path: "/index",
    name: "Index",
    meta: {
      title: "掘铁 - 代码不止，掘铁不止"
    },
    component: () => import("../views/index/index.vue")
  },
  {
    path: "/article/:id",
    name: "Article",
    component: () => import("../views/article/article.vue")
  },
  {
    path: "/user/:id",
    name: "User",
    component: () => import("../views/user/User.vue"),
    children:[
      {
          path: "/user/:id",
          redirect: "/user/:id/activities"
      },
      {
          path: "/user/:id/activities",
          name: "Activities",
          component: () => import("../views/user/Activities.vue")
      },
      {
          path: "/user/:id/likes",
          name: "Likes",
          component: () => import("../views/user/Likes.vue")
      },
      {
          path: "/user/:id/pins",
          name: "Pins",
          component: () => import("../views/user/Pins.vue")
      },
      {
          path: "/user/:id/posts",
          name: "Posts",
          component: () => import("../views/user/Posts.vue")
      },
      {
          path: "/user/:id/praise",
          name: "Praise",
          component: () => import("../views/user/Praise.vue")
      },
      {
          path: "/user/:id/tags",
          name: "Tags",
          component: () => import("../views/user/Tags.vue")
      },
      {
          path: "/user/:id/followers",
          name: "Followers",
          component: () => import("../views/user/Followers.vue")
      },
      {
          path: "/user/:id/following",
          name: "Following",
          component: () => import("../views/user/Following.vue")
      },
      {
          path: "/user/:id/cposts",
          name: "Cposts",
          component: () => import("../views/user/Cposts.vue")
      }
    ]
  },
  {
    path: "/userAgree",
    name: "userAgree",
    component: () => import("../views/index/userAgree.vue")
  },
  {
    path: "/privacyPolicy",
    name: "privacyPolicy",
    component: () => import("../views/index/privacyPolicy.vue")
  },
  {
    path: "/authorRanking",
    name: "authorRanking",
    component: () => import("../views/index/authorRanking.vue")
  },
  {
    path: "/profile",
    name: "profile",
    component: () => import("../views/profile/profile.vue")
  },
  {
    path: "/account",
    name: "account",
    component: () => import("../views/account/account.vue")
  },
  {
    path: "/report",
    name: "report",
    component: () => import("../views/report/report.vue")
  },

{
    path: "/back",
    name: "back",
    component: () => import("../components/back.vue")//后台
  },
  {
    path: "/addit",
    name: "addit",
    component: () => import("../views/index/addit.vue")//新增帖子
  },
  {
    path: "/pins",
    name: "pins",
    component: () => import("../views/pins/pins.vue")//沸点
  }

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
